package com.hikeen.launcherx;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

import com.hikeen.launcherx.ui.MainActivity3;
import com.hikeen.launcherx.utils.AppUtils;
import com.hikeen.launcherx.utils.L;
import com.hikeen.launcherx.utils.SPUtils;
import com.hjq.toast.ToastInterceptor;
import com.hjq.toast.ToastUtils;


import org.greenrobot.eventbus.EventBus;


public class MyApplication extends Application {
    public static String yuyan = "zh";
    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
//        setTheme(R.style.AppTheme);
        mContext = getApplicationContext();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                initSDK(MyApplication.this);
            }
        }, 100);

    }


    public void testevent(String replacepackageName, String type) {
        Log.e("logee   MyApplication", "testevent: ");
        if (type.equals("addapp")) {

            MainActivity3.threeFramgent.chushihua("");
            MainActivity3.twoFramgent.chushihua();

        } else {

            MainActivity3.threeFramgent.chushihua(replacepackageName);
            MainActivity3.twoFramgent.chushihua();
        }

    }


    /**
     * 初始化一些第三方框架
     */
    public void initSDK(Application application) {

        SPUtils.init(this);   //这句加到Application

        // 设置 Toast 拦截器
        ToastUtils.setToastInterceptor(new ToastInterceptor() {
            @Override
            public boolean intercept(Toast toast, CharSequence text) {
                boolean intercept = super.intercept(toast, text);
                if (intercept) {
                    Log.e("Toast", "空 Toast");
                } else {
                    Log.i("Toast", text.toString());
                }
                return intercept;
            }
        });
        // 吐司工具类
        ToastUtils.init(application);


        // EventBus 事件总线
//        EventBusManager.init();

        AppUtils.init(application);

        L.init(true);
        // 设置崩溃后自动重启 APP
        // 参数依次为 上下文（建议是Application），是否是debug模式，是否崩溃后重启，重启延迟时间，重启的Activity
//        UncaughtExceptionHandlerImpl.getInstance().init(application, BuildConfig.DEBUG, true, 0, HomeCameraActivity.class);

//        EventBus.builder()
//                // 使用 Apt 插件
//                .ignoreGeneratedIndex(false)
//                // 添加索引类
//                .addIndex(new MyEventBusIndex())
//                // 作为默认配置
//                .installDefaultEventBus();


    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);

    }


    public static Context getContext() {
        return mContext;
    }
}
